import Taro, { Component } from '@tarojs/taro'
import { Image, Swiper, SwiperItem } from '@tarojs/components'
import { toAnyPage } from '@/utils/page_router'

interface IProps {
  list: any
}

/**
 * 首页轮播
 */
export default class Index extends Component<IProps, {}> {
  props: any
  render() {
    const { list=[] } = this.props
    const height = list.length && (list.length > 1 ? list.reduce((a , b) => (b.h > a.h ? b.h : a.h)) : list[0].h)
    return (<Swiper circular autoplay={list.length > 1} className='carousel-one' style={{height: `${height}rpx`}}>
      {list.map((ad, k) => {
        return (<SwiperItem key={k} className='ad-item' onClick={() => toAnyPage(ad.url)}>
          <Image src={ad.pic} className='ad-img'/>
        </SwiperItem>)
      })}
    </Swiper>)
  }
}
